package com.baidumap.administrator.happystudy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.baidumap.administrator.happystudy.R;

import java.util.ArrayList;
import java.util.List;

/**
 * author: C on 2017/3/21.
 * 分类：左边
 */
public class TypeLeftAdapter extends BaseAdapter{
    private Context mContext;
    private List<String> datas = null;
    private int mCurrentPosition;

    public TypeLeftAdapter(Context context) {
        mContext = context;
        datas = new ArrayList<>();
        datas.add("服装鞋帽");
        datas.add("美食");
        datas.add("数码电子");
        datas.add("超市");
        datas.add("医疗医药");
        datas.add("名贵药酒");
        datas.add("汽车服务");
        datas.add("建材家具");
        datas.add("生活服务");
    }

    public void changeSelected(int position) {
        if (mCurrentPosition != position) {
            mCurrentPosition = position;
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_type_left, null);
            viewHolder.tvTypeName = (TextView)convertView.findViewById(R.id.tv_name);
            viewHolder.ivCheck = convertView.findViewById(R.id.view_check);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder)convertView.getTag();
        }

        if (mCurrentPosition == position) {
            viewHolder.tvTypeName.setBackgroundResource(R.color.white);
            viewHolder.ivCheck.setVisibility(View.VISIBLE);
        } else {
            viewHolder.tvTypeName.setBackgroundResource(R.color.gray_e1);
            viewHolder.ivCheck.setVisibility(View.GONE);
        }

        viewHolder.tvTypeName.setText(datas.get(position));

        return convertView;
    }
    class ViewHolder {
        private TextView tvTypeName;
        private View ivCheck;
    }
}
